############
# Figure 1 #
############
data <- read.csv("senator-approval.csv")

par(mar=c(3,3.2,1,3.4), mgp=c(1.5,.05,0),mfrow=c(1,1))
plot(data$approval[data$sen_pid=="R"]*100,data$no[data$sen_pid=="R"],col="RED",pch=18,xaxt="n",yaxt="n",tck=0,
     ylab="",xlab="",xlim=c(30,80),ylim=c(3,98))
points(data$approval[data$sen_pid=="D"]*100,data$no[data$sen_pid=="D"],col="BLUE",pch=20)
# Democrat names on left of figure
axis(2, at=data$no[data$sen_pid=="D"],labels=data$name[data$sen_pid=="D"], cex.axis=0.6, las=2,tck=0)
# Republican names on right of figure
axis(4, at=data$no[data$sen_pid=="R"],labels=data$name[data$sen_pid=="R"], cex.axis=0.6, las=2,tck=0)
axis(1, at=c(30,40,50,60,70,80),labels=c(30,40,50,60,70,80), cex.axis=0.75,tck=0)
title(xlab="Senator approval ratings (percentage points)")
abline(v=55.7,col="GREY")
abline(v=39.9,col="GREY")
text(59,95,"Average \nSenator \napproval\n(55.7)",cex=0.8)
text(43.1,75,"Bush \napproval\n(39.9)",cex=0.8)
mtext(side=2,at=c(103),"Democrats",cex=0.7, las=2, font=2)
mtext(side=4,at=c(103),"Republicans",cex=0.7, las=2, font=2)
legend(70,10, c("Democrat","Republican"), pch=c(20,18), 
       col=c("blue","red"),cex=0.75,pt.cex=1.5)
